package com.qf.hotel.controller.foodtype;

import com.qf.hotel.pojo.FoodType;
import com.qf.hotel.service.FoodTypeService;
import com.qf.hotel.service.impl.FoodTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/foodtype/findById")
public class FoodTypeFindByIdController extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 字符编码设置
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        try {
            // 收参--id--typeId
            String typeId = request.getParameter("typeId");

            // 调用业务方法查询
            FoodTypeService foodTypeService = new FoodTypeServiceImpl();
            FoodType foodType = foodTypeService.findById(Integer.parseInt(typeId));

            // 把foodType对象放入域
            request.setAttribute("foodType",foodType);

            // 转发请求到修改页面
            request.getRequestDispatcher("/backend/detail/foodtype/foodtype-update.jsp").forward(request,response);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
